//
//  LGTAdviceFeedVC.swift
//  KJLGT
//
//  Created by jenkin on 2019/9/2.
//  Copyright © 2019年 jenkin. All rights reserved.
//

import UIKit
import WisdomHUD

class LGTAdviceFeedVC: LGTBaseVC {

    var textView:LGTInputTextView?
    var textView2:LGTInputTextView?
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    
    override func setUI() {
        super.setUI()
        
        self.setBavBarStyle(navBarHiden: false, title: "意见反馈", back: true)
        self.view.backgroundColor = ViewBackColor
        
        let firstView:UIView = UIView.init()
        firstView.backgroundColor = UIColor.white
        self.view.addSubview(firstView)
        firstView.snp.makeConstraints { (make) in
            make.left.right.equalTo(0)
            make.height.equalTo(SizeFit(206))
            make.top.equalTo(NavBarH + SizeFit(12))
        }
        
        let line:UIView = UIView.init()
        line.backgroundColor = YellowColor
        firstView.addSubview(line)
        line.snp.makeConstraints { (make) in
            make.left.equalTo(SizeFitFloat(12))
            make.height.equalTo(SizeFitFloat(15))
            make.width.equalTo(SizeFitFloat(3))
            make.top.equalTo(SizeFit(21))
        }
        
        let label:UILabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: 0, text: "请填写您的反馈，我们将会不断改进")
        label.font = KBFont(size: 15)
        firstView.addSubview(label)
        label.snp.makeConstraints { (make) in
            make.centerY.equalTo(line)
            make.height.equalTo(SizeFit(16))
            make.left.equalTo(SizeFit(25))
        }
        
        self.textView = LGTViewCreateUtil.share.createInputTextView(placehoder:"请输入您的反馈", fontSize:SizeFitFloat(12), limitCout:300, showCount:true)
        firstView.addSubview(self.textView!)
        self.textView?.snp.makeConstraints({ (make) in
            make.left.equalTo(SizeFit(7))
            make.right.equalTo(SizeFit(-12))
            make.top.equalTo(line.snp_bottomMargin).offset(SizeFit(18))
            make.height.equalTo(SizeFit(140))
        })
        
        
        
//        let seconView:UIView = UIView.init()
//        seconView.backgroundColor = UIColor.white
//        self.view.addSubview(seconView)
//        seconView.snp.makeConstraints { (make) in
//            make.left.right.equalTo(0)
//            make.height.equalTo(SizeFit(160))
//            make.top.equalTo(firstView.snp_bottomMargin).offset(SizeFitFloat(20))
//        }
//
//        let line2:UIView = UIView.init()
//        line2.backgroundColor = YellowColor
//        seconView.addSubview(line2)
//        line2.snp.makeConstraints { (make) in
//            make.left.equalTo(SizeFitFloat(12))
//            make.height.equalTo(SizeFitFloat(15))
//            make.width.equalTo(SizeFitFloat(3))
//            make.top.equalTo(SizeFit(21))
//        }
//
//        let label2:UILabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: 0, text: "请留下您的联系方式")
//        label2.font = KBFont(size: 15)
//        seconView.addSubview(label2)
//        label2.snp.makeConstraints { (make) in
//            make.centerY.equalTo(line2)
//            make.height.equalTo(SizeFit(16))
//            make.left.equalTo(SizeFit(25))
//        }
//
//        self.textView2 = LGTViewCreateUtil.share.createInputTextView(placehoder:"手机号、QQ或邮箱等联系方式", fontSize:SizeFitFloat(12), limitCout:300)
//        seconView.addSubview(self.textView2!)
//        self.textView2?.snp.makeConstraints({ (make) in
//            make.left.equalTo(SizeFit(7))
//            make.right.equalTo(SizeFit(-12))
//            make.top.equalTo(line2.snp_bottomMargin).offset(SizeFit(18))
//            make.height.equalTo(SizeFit(100))
//        })
        
        let button:UIButton = LGTViewCreateUtil.share.createTextLGTButton(title: "确认提交", font: Font_Normal_18, color: UIColor.white, selectedColor: UIColor.white, corner: SizeFitFloat(22))
        button.backgroundColor = YellowColor
        self.view.addSubview(button)
        button.snp.makeConstraints { (make) in
            make.height.equalTo(SizeFitFloat(44))
            make.centerX.equalTo(self.view)
            make.top.equalTo(firstView.snp_bottomMargin).offset(SizeFitFloat(61))
            make.width.equalTo(SizeFitFloat(266))
        }
        button.addTarget(self, action: #selector(submitAction), for: UIControl.Event.touchUpInside)
    }
    
    @objc func submitAction(){
        if self.textView?.text?.count == 0 {
             WisdomHUD.showError(text: "请填写您的反馈")
            return
        }
        
//        if self.textView2?.text?.count == 0 {
//            WisdomHUD.showError(text: "请留下您的联系方式")
//            return
//        }
        
        let question:String = self.textView?.text ?? ""
        let param = ["question": question]
        self.updateUserInfo(dict: param, showMessage: true)
    }
    
    func updateUserInfo(dict:Dictionary<String, Any>, showMessage:Bool = true){
        weak var weakSelf = self
        LGTHttpUtil.httpUtil.requestData(url: Advice_URL, param: dict, showMessage: showMessage, success: { (json) in
            weakSelf?.navigationController?.popViewController(animated: true)
        }) { (json) in

        }
    }

}
